<%@ page import="org.parademo.service.security.ParademoUser" %>
<%@ page import="org.springframework.security.authentication.AnonymousAuthenticationToken" %>
<%@ page import="org.springframework.security.core.Authentication" %>
<%@ page import="org.springframework.security.core.context.SecurityContext" %>
<%@ page import="org.springframework.security.core.context.SecurityContextHolder" %>
<%@ page import="org.springframework.security.core.userdetails.User" %>
<%@ page import="org.parademo.service.security.SecurityUtil" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>

<%--@elvariable id="users" type="java.util.List<org.parademo.model.UserEntity>"--%>
<%

    ParademoUser currentUser = SecurityUtil.getCurrentUser();
    if (currentUser == null) {
        request.setAttribute("user", "Stranger");
    } else {
        request.setAttribute(
                "user",
                currentUser.getFirstName() + " " + currentUser.getLastName() + " (" + currentUser.getUsername() + ")"
        );
    }
%><html>

<head>
    <title>Users</title>
    <style type="text/css">
        .clear {
            clear: both;
        }

        ul.buttons {
            float: right;
            list-style: none;
            padding: 0;
            margin: 0;
        }

        ul.buttons li {
            float: left;
            margin-left: 15px;
        }

        .credentialsBar {
            padding-bottom: 20px;
        }
    </style>
</head>

<body>

<!-- buttons -->
<div class="credentialsBar">
    <ul class="buttons">
        <li>${user}</li>
        <li><a href="<c:url value="/j_spring_security_logout" />">Sign Out</a></li>
    </ul>
    <div class="clear"></div>
</div>

<!-- user list -->
<table border="1">
    <thead>
        <tr>
            <th>ID</th>
            <th>Username</th>
            <th>First name</th>
            <th>Last name</th>
            <th>Join date</th>
            <th>Birth date</th>
            <th>Address</th>
        </tr>
    </thead>
    <tbody>
    <c:forEach items="${users}" var="user">
        <tr>
            <td>${user.id}</td>
            <td>${user.userName}</td>
            <td>${user.firstName}</td>
            <td>${user.lastName}</td>
            <td>${user.joinDate}</td>
            <td>${user.birthDate}</td>
            <td>${user.address}</td>
        </tr>
    </c:forEach>
    </tbody>
</table>

</body>

</html>